package translated;

import java.util.List;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.jet.util.*;

public class FactoryGen
{
  protected static String nl;
  public static synchronized FactoryGen create(String lineSeparator)
  {
    nl = lineSeparator;
    FactoryGen result = new FactoryGen();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "/**" + NL + " * Copyright (c) Software Institude of PKU" + NL + " * All rights reserved. " + NL + " * This program and the accompanying materials" + NL + " * are made available under the terms of the Eclipse Public License v1.0" + NL + " * which accompanies this distribution, and is available at" + NL + " * http://www.eclipse.org/legal/epl-v10.html" + NL + " *" + NL + "*/" + NL + "package ";
  protected final String TEXT_2 = ";" + NL + "// imports:" + NL + "import edu.pku.sei.modeler.model.common.*;" + NL + "import edu.pku.sei.modeler.model.core.MetaElement;" + NL + "import edu.pku.sei.modeler.model.core.MetaPackage;" + NL + "import edu.pku.sei.modeler.model.core.MetaModel;";
  protected final String TEXT_3 = NL + "import ";
  protected final String TEXT_4 = ".*;";
  protected final String TEXT_5 = NL + NL + "/**" + NL + " * @generated" + NL + " *" + NL + " */" + NL + "public class ModelFactory extends AbstractFactory {" + NL + "\tpublic Object createRootElement(boolean register) {" + NL + "\t\treturn null;" + NL + "\t}" + NL + "\tpublic Object createElement(String typeString, boolean register) {" + NL + "\t\tMetaElement element = null;" + NL + "\t\telementCount ++;" + NL + "\t\tif(typeString.equals(";
  protected final String TEXT_6 = ".__METAPACKAGE__)) {" + NL + "\t\t\telement = new MetaPackage();" + NL + "\t\t}" + NL + "\t\telse if(typeString.equals(";
  protected final String TEXT_7 = ".__METAMODEL__)) {" + NL + "\t\t\telement = new MetaModel();" + NL + "\t\t}" + NL + "\t\t";
  protected final String TEXT_8 = NL + "\t\telse if(typeString.equals(";
  protected final String TEXT_9 = ")) {" + NL + "\t\t\telement = new ";
  protected final String TEXT_10 = "();" + NL + "\t\t}" + NL + "\t\t";
  protected final String TEXT_11 = NL + "\t\t" + NL + "\t\tif(element == null)return null;" + NL + "\t\telement.setElementID(elementCount);" + NL + "\t\tif(register) {" + NL + "\t\t\tregisterToPackage(element, typeString);" + NL + "\t\t}" + NL + "\t\treturn element;" + NL + "\t}" + NL + "\tpublic MetaPackage createMetaPackage() {" + NL + "\t\treturn (MetaPackage)createElement(";
  protected final String TEXT_12 = ".__METAPACKAGE__, true);" + NL + "\t}" + NL + "\t";
  protected final String TEXT_13 = NL + "\tpublic ";
  protected final String TEXT_14 = " create";
  protected final String TEXT_15 = "() {" + NL + "\t\treturn (";
  protected final String TEXT_16 = ")createElement(";
  protected final String TEXT_17 = ", true);" + NL + "\t}" + NL + "\t";
  protected final String TEXT_18 = NL + "}";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     List modelList = (List) argument; 
    stringBuffer.append(TEXT_1);
    stringBuffer.append(ModelerConstants.pkgBase + "." + ModelerConstants.modelBase);
    stringBuffer.append(TEXT_2);
    
	List pkgPaths = PackageRetriever.pkgPathList;
	for(int i=0; i<pkgPaths.size(); i++) {

    stringBuffer.append(TEXT_3);
    stringBuffer.append(pkgPaths.get(i));
    stringBuffer.append(TEXT_4);
    
	}

    stringBuffer.append(TEXT_5);
    stringBuffer.append(ModelerConstants.modelPackage);
    stringBuffer.append(TEXT_6);
    stringBuffer.append(ModelerConstants.modelPackage);
    stringBuffer.append(TEXT_7);
    
		for(int i=0; i<modelList.size(); i++) {
			MetaClass cls = (MetaClass)modelList.get(i);
			if(cls.isAbstract())continue;
			String clsID = PackageRetriever.retrieveClassID(cls);
		
    stringBuffer.append(TEXT_8);
    stringBuffer.append(clsID);
    stringBuffer.append(TEXT_9);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_10);
    
		}
		
    stringBuffer.append(TEXT_11);
    stringBuffer.append(ModelerConstants.modelPackage);
    stringBuffer.append(TEXT_12);
    
	for(int i=0; i<modelList.size(); i++) {
		MetaClass cls = (MetaClass)modelList.get(i);
		if(cls.isAbstract())continue;
		String clsID = PackageRetriever.retrieveClassID(cls);
	
    stringBuffer.append(TEXT_13);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_14);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_15);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_16);
    stringBuffer.append(clsID);
    stringBuffer.append(TEXT_17);
    
	}
	
    stringBuffer.append(TEXT_18);
    return stringBuffer.toString();
  }
}
